﻿Friend Class MultipleFilesInput
    Inherits ModelBase
    Implements IMultipleFilesInput

#Region "Events"
    ' Insert Event Declarations Here
#End Region

#Region "Properties"
#Region "Constants"
    ' Insert Constant Declarations Here
#End Region

    Private _rootDirectoryPath As String
    Public Property RootDirectoryPath() As String Implements IMultipleFilesInput.RootDirectoryPath
        Get
            Return _rootDirectoryPath
        End Get
        Set(ByVal value As String)
            If _rootDirectoryPath <> value Then
                _rootDirectoryPath = value
                MyBase.OnPropertyChanged()
            End If
        End Set
    End Property

    Private _includeSubDirectories As Boolean = True
    Public Property IncludeSubDirectories() As Boolean Implements IMultipleFilesInput.IncludeSubDirectories
        Get
            Return _includeSubDirectories
        End Get
        Set(ByVal value As Boolean)
            If _includeSubDirectories <> value Then
                _includeSubDirectories = value
                Me.OnPropertyChanged()
            End If
        End Set
    End Property

    Private _fileNameFilter As String = ""
    Public Property FileNameFilter() As String Implements IMultipleFilesInput.FileNameFilter
        Get
            Return _fileNameFilter
        End Get
        Set(ByVal value As String)
            If _fileNameFilter <> value Then
                _fileNameFilter = value
                Me.OnPropertyChanged()
            End If
        End Set
    End Property

    Private _hierarchicalResults As Boolean
    Public Property HierarchicalResults As Boolean Implements IMultipleFilesInput.HierarchicalResults
        Get
            Return _hierarchicalResults
        End Get
        Set(value As Boolean)
            If _hierarchicalResults <> value Then
                _hierarchicalResults = value
                MyBase.OnPropertyChanged()
            End If
        End Set
    End Property
#End Region

#Region "Constructors"
    ' Insert Constructor Declarations Here
#End Region

#Region "Methods"
    Public Function GetFileList() As IEnumerable(Of IO.FileInfo)
        Dim l_fileNameFilter As Regex
        Try
            l_fileNameFilter = New Regex(Me.FileNameFilter)
        Catch ex As ArgumentException
            l_fileNameFilter = Nothing
        End Try
        If IO.Directory.Exists(Me.RootDirectoryPath) AndAlso l_fileNameFilter IsNot Nothing Then
            Dim l_files =
                From l_fileName In IO.Directory.GetFiles(Me.RootDirectoryPath, "*", IO.SearchOption.AllDirectories)
                Where l_fileNameFilter.IsMatch(l_fileName)
                Select New IO.FileInfo(l_fileName)

            Return l_files
        Else
            Return New IO.FileInfo() {}
        End If
    End Function

#Region "Event Raiser Methods"
    ' Insert Method Declarations which Raise an Event Here
#End Region

#Region "Event Handlers"
    ' Insert Method Declarations which Handle an Event Here
#End Region
#End Region

End Class
